#

# sql = "insert person value('amidn',10,2000,'男')"

import pymysql


def insert(sql,param):
    con = pymysql.connect(host="localhost", user="root", password="root", database="bank")
    cur = con.cursor()  # 创建控制台
    cur.execute(sql,param)
    con.commit()  # 提交到数据库
    print("已经更改数据库")
    cur.close()
    con.close()


# insert(sql)

def select(sql,param,mode="all",size=0):
    con = pymysql.connect(host="localhost", user="root", password="root", database="bank")
    cur = con.cursor()  # 创建控制台
    cur.execute(sql,param)
    if mode == "all":
        return cur.fetchall()
    elif mode == "one":
        return cur.fetchone()
    elif mode == "many":
        return cur.fetchmany(size=size)
    cur.close()
    con.close()

def Change(sql,param):
    con = pymysql.connect(host="localhost",user="root",password="root",database="bank")
    cur = con.cursor()
    cur.execute(sql,param)
    con.commit()
    cur.close()
    con.close()

# sql = "select username,password from user where username = %s and password = %s"
# param = ["ssr","21"]
# print(select(sql, param, mode="one"))
# sql = "select * from user where username = %s"
# p = "ssr"
# print(select(sql, p, mode="one"))
# key1 = "select username from user where username = %s"
# para = "1"
# print(select(key1, para, mode="one"))
#
# key = "select username from user "

# li = select(key,param=None,mode="all")
# for i in li:
#     print(i[0])
# sql = "select username  from user "
# print(select(sql))
# # acoount=2345
# password=23456

# sql = "select  username,password from user where username=%s  and password=%s"
# p = ["ssr","11"]
# sql1 = "select * from user where username = %s"
# p1 = "ssr"
# print(select(sql1, p1, mode="one"))
# if select(sql, p,mode="one") is None:#,
#     print("不存在")
# else:
#     print("存在")